﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../lib/layui/layui.js"></script>

    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <style>
        .layui-form .layui-form-item{
            margin-right:20px;
        }
    </style>
</head>
<body>
    <div class="layui-btn-fluid">

        <form class="layui-form" lay-filter="updXpathForm">
            <div class="layui-form-item" style="margin-top:20px;">
                <label class="layui-form-label">原xpath</label>
                <div class="layui-input-block">
                    <input type="text" name="oldXpath" id="oldXpath" required class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">新xpath</label>
                <div class="layui-input-block">
                    <input type="text" name="newXpath" id="newXpath" required class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item" style="text-align:center;">
                <a class="layui-btn" href="javascript:;" lay-submit lay-filter="saveXpath">保存</a>
            </div>
        </form>

    </div>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        };
        layui.use(['form'], function () {
            var form = layui.form;
            var $ = layui.$;
            //保存xpath
            form.on('submit(saveXpath)', function (data) {
                data.elem.removeAttribute("lay-submit");
                var data = data;
                layer.confirm('确认要修改xPath路径吗？', function (index) {
                    var i = layui.layer.load();
                    //发异步删除数据
                    layui.$.ajax({
                        type: 'post',
                        url: localStorage.getItem('hosttingaddr') + '/api/main/updateconfigxpath',
                        headers: {
                            user: getCookie("userinfo"),
                            version: getCookie("version")
                        },
                        dataType: 'json',
                        data: data.field,
                        success: function (res) {
                            layui.layer.close(i);
                            var icon = 1;
                            if (res.code != 0) {
                                icon = 5;
                            }
                            layer.alert(res.msg, { icon: icon, skin: 'layui-layer-molv' }, function () {
                                var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                                parent.layer.close(index);
                            });
                        },
                        error: function (res) {
                            layui.layer.close(i);
                            layer.alert("更新异常", { icon: 5, skin: 'layui-layer-molv' }, function () {
                                var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                                parent.layer.close(index);
                            });
                        }
                    });
                });
                return false;
            });
        })
    </script>
</body>
</html>
